package com.hqully.labmanage.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.labmanage.domain.dto.DeviceFaultRecordDTO;
import com.hqully.labmanage.domain.dto.FaultRecordReadDTO;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.ResultVO;
import com.hqully.labmanage.service.DeviceFaultRecordService;
import com.hqully.labmanage.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备故障记录数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-08 11:17:19
 */
@Api(tags = {"设备故障记录数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/device-fault-record")
public class DeviceFaultRecordController extends BaseController {

    @Resource
    private DeviceFaultRecordService deviceFaultRecordService;


    @ApiOperation(value = "分页条件查询设备故障记录列表")
    @PostMapping("/read-fault-record")
    public ResultVO<PageInfo<DeviceFaultRecordDTO>> readFaultRecord(@RequestBody FaultRecordReadDTO faultRecordReadDTO) {
        deviceFaultRecordService.readFaultRecord(faultRecordReadDTO);
        return ResultVOUtil.success("已读故障成功");
    }
    @ApiOperation(value = "分页条件查询设备故障记录列表")
    @GetMapping("/page-device-fault-records")
    public ResultVO<PageInfo<DeviceFaultRecordDTO>> pageDeviceFaultRecords(PageDTO page, DeviceFaultRecordDTO deviceFaultRecordDTO) {
        PageInfo<DeviceFaultRecordDTO> deviceFaultRecordPage = deviceFaultRecordService.pageDeviceFaultRecords(page, deviceFaultRecordDTO);
        return ResultVOUtil.success(deviceFaultRecordPage);
    }

    @ApiOperation(value = "条件查询设备故障记录列表")
    @GetMapping("/list-device-fault-records")
    public ResultVO<List<DeviceFaultRecordDTO>> listDeviceFaultRecords(DeviceFaultRecordDTO deviceFaultRecordDTO) {
        List<DeviceFaultRecordDTO> deviceFaultRecordList = deviceFaultRecordService.listDeviceFaultRecords(deviceFaultRecordDTO);
        return ResultVOUtil.success(deviceFaultRecordList);
    }

    @ApiOperation(value = "添加设备故障记录")
    @PostMapping("/add-device-fault-record")
    public ResultVO<DeviceFaultRecordDTO> addDeviceFaultRecord(@Validated @RequestBody DeviceFaultRecordDTO deviceFaultRecordDTO) {
        deviceFaultRecordService.addDeviceFaultRecord(deviceFaultRecordDTO);
        return ResultVOUtil.success("添加设备故障记录成功");
    }

    @ApiOperation(value = "更新设备故障记录")
    @PostMapping("/update-device-fault-record")
    public ResultVO<DeviceFaultRecordDTO> updateDeviceFaultRecord(@Validated @RequestBody DeviceFaultRecordDTO deviceFaultRecordDTO) {
        deviceFaultRecordService.updateDeviceFaultRecord(deviceFaultRecordDTO);
        return ResultVOUtil.success("更新设备故障记录成功");
    }

    @ApiOperation(value = "删除设备故障记录")
    @DeleteMapping("/delete-device-fault-record/{id}")
    public ResultVO<DeviceFaultRecordDTO> deleteDeviceFaultRecord(@PathVariable("id") Integer id) {
        deviceFaultRecordService.deleteDeviceFaultRecordById(id);
        return ResultVOUtil.success("删除设备故障记录成功");
    }

}

